<template>
	<el-main class="bg table_wrap comtabel_t">
		<el-form label-position="right" :model="query" class="form p_4" label-width="120">
			<el-row class="rows row1">



										<el-col :xs="24" :sm="24" :lg="8" class="el_form_search_wrap">
					<el-form-item label="项目编号">
									<el-input v-model="query.project_number"></el-input>
								</el-form-item>
				</el-col>
									<el-col :xs="24" :sm="24" :lg="8" class="el_form_search_wrap">
					<el-form-item label="项目名称">
									<el-input v-model="query.entry_name"></el-input>
								</el-form-item>
				</el-col>
																		<el-col :xs="24" :sm="24" :lg="8" class="el_form_search_wrap">
					<el-form-item label="团队名称">
									<el-input v-model="query.team_name"></el-input>
								</el-form-item>
				</el-col>
																</el-row>
	<el-row class="rows row2">

		<el-col :xs="24" :sm="24" :lg="24" class="search_btn_wrap search_btns">

				<el-col :xs="24" :sm="10" :lg="8" class="search_btn_1 search_btn_wrap_1 btns">

										<el-button type="primary" @click="search()" class="search_btn_find">查询</el-button>
						<el-button @click="reset()" style="margin-right: 74px;" class="search_btn_reset">重置</el-button>
																		

						<el-button v-if="$check_action('/project_team/table','del') || $check_action('/project_team/view','del')" class="search_btn_del" type="danger" @click="delInfo()">删除</el-button>
								
				</el-col>
		</el-col>
	</el-row >

		</el-form>
				<el-table :data="list" @selection-change="selectionChange" @sort-change="$sortChange" style="width: 100%" id="dataTable">
					<el-table-column fixed type="selection" tooltip-effect="dark" width="55">
			</el-table-column>
				<el-table-column prop="project_manager" @sort-change="$sortChange" label="项目经理" 				v-if="$check_field('get','project_manager')" min-width="200">
						<template slot-scope="scope">
					{{ get_user_project_manager(scope.row['project_manager']) }}
				</template>
					</el-table-column>
					<el-table-column prop="project_number" @sort-change="$sortChange" label="项目编号" 				v-if="$check_field('get','project_number')" min-width="200">
					</el-table-column>
					<el-table-column prop="entry_name" @sort-change="$sortChange" label="项目名称" 				v-if="$check_field('get','entry_name')" min-width="200">
					</el-table-column>
					<el-table-column prop="project_budget" @sort-change="$sortChange" label="项目预算" 				v-if="$check_field('get','project_budget')" min-width="200">
					</el-table-column>
					<el-table-column prop="start_date" @sort-change="$sortChange" label="开始日期" 				v-if="$check_field('get','start_date')" min-width="200">
					</el-table-column>
					<el-table-column prop="closing_date" @sort-change="$sortChange" label="截止日期" 				v-if="$check_field('get','closing_date')" min-width="200">
					</el-table-column>
					<el-table-column prop="team_name" @sort-change="$sortChange" label="团队名称" 				v-if="$check_field('get','team_name')" min-width="200">
					</el-table-column>
					<el-table-column prop="team_size" @sort-change="$sortChange" label="团队人数" 				v-if="$check_field('get','team_size')" min-width="200">
					</el-table-column>
					<el-table-column prop="development_member" @sort-change="$sortChange" label="开发成员" 				v-if="$check_field('get','development_member')" min-width="200">
					</el-table-column>
					<el-table-column prop="test_member" @sort-change="$sortChange" label="测试成员" 				v-if="$check_field('get','test_member')" min-width="200">
					</el-table-column>
					<el-table-column prop="team_division_of_labor" @sort-change="$sortChange" label="团队分工" 				v-if="$check_field('get','team_division_of_labor')" min-width="200">
					</el-table-column>
	


            <el-table-column sortable prop="create_time" label="创建时间" min-width="200">
                <template slot-scope="scope">
                	{{ $toTime(scope.row["create_time"],"yyyy-MM-dd hh:mm:ss") }}
                </template>
            </el-table-column>

			<el-table-column sortable prop="update_time" label="更新时间" min-width="200">
                <template slot-scope="scope">
                	{{ $toTime(scope.row["update_time"],"yyyy-MM-dd hh:mm:ss") }}
                </template>
			</el-table-column>







			<el-table-column fixed="right" label="操作" min-width="200" v-if="$check_action('/project_team/table','set') || $check_action('/project_team/view','set') || $check_action('/project_team/view','get') 
						|| $check_action('/task_allocation/table','add') || $check_action('/task_allocation/view','add') 
						|| $check_action('/cost_report/table','add') || $check_action('/cost_report/view','add') 
						" >


				<template slot-scope="scope">
					<div class="view_a">
					<router-link class="e-button el-button--small is-plain el-button--success" style="margin: 5px !important;"
					v-if="$check_action('/project_team/table','set') || $check_action('/project_team/view','set') || $check_action('/project_team/view','get')"
						:to="'./view?' + field + '=' + scope.row[field]"
						 size="small">
						<span>详情</span>
					</router-link>
						<!--跨表按钮-->
										<el-button class="e-button el-button--small is-plain el-button--primary" style="margin: 5px !important;" size="small" @click="to_table(scope.row,'/task_allocation/view')" v-if="($check_action('/task_allocation/table','add') || $check_action('/task_allocation/view','add')) && !scope.row['task_allocation_limit']">
						<span>分配任务</span>
					</el-button>
													<el-button class="e-button el-button--small is-plain el-button--primary" style="margin: 5px !important;" size="small" @click="to_table(scope.row,'/cost_report/view')" v-if="($check_action('/cost_report/table','add') || $check_action('/cost_report/view','add')) && !scope.row['cost_report_limit']">
						<span>成本</span>
					</el-button>
										</div>
				</template>
			</el-table-column>

		</el-table>

		<!-- 分页器 -->
		<div class="mt text_center">
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page="query.page" :page-sizes="[7, 10, 30, 100]" :page-size="query.size"
				layout="total, sizes, prev, pager, next, jumper" :total="count">
			</el-pagination>
		</div>
		<!-- /分页器 -->
											
		<div class="modal_wrap" v-if="showModal">
			<div class="modal_box">
				<!-- <div class="modal_box_close" @click="closeModal">X</div> -->
				<p class="modal_box_title">重要提醒</p>
				<p class="modal_box_text">当前有数据达到预警值！</p>
				<p class="modal_box_text">{{ message }}</p>
				<div class="btn_box">
					<span @click="closeModal">取消</span>
					<span @click="closeModal">确定</span>
				</div>
			</div>
		</div>


	</el-main>
</template>
<script>
	import mixin from "@/mixins/page.js";

	export default {
		mixins: [mixin],
		data() {
			return {
				// 弹框
				showModal: false,
				// 获取数据地址
				url_get_list: "~/api/project_team/get_list?like=0",
				url_del: "~/api/project_team/del?",

				// 字段ID
				field: "project_team_id",

				// 查询
				query: {
					"size": 7,
					"page": 1,
									"project_number": "",
											"entry_name": "",
														"team_name": "",
												"login_time": "",
					"create_time": "",
					"orderby": `create_time desc`
				},

				// 数据
				list: [],
																			// 用户列表
				list_user_project_manager: [],
																									message: '',
			}
		},
		methods: {
			// 关闭弹框
			closeModal(){
				this.showModal = false;
				},
			/**
			 * @description 获取到列表事件
			 * @param {Object} res 响应结果
			 */
			get_list_after: function get_list_after(res, func, url) {
				let _this = this
													_this.list.map((item) => {
					let param = {
						source_table: "project_team",
						source_id: item.project_team_id,
						source_user_id: _this.user.user_id
					};
					if(item.task_allocation_limit_times > 0){
						_this.$get("~/api/task_allocation/count?",param,(result)=>{
							if(result){
								if(result.result >= item.task_allocation_limit_times){
									_this.$set(item,'task_allocation_limit',true);
								}else{
									_this.$set(item,'task_allocation_limit',false);
								}
							}
						})
					}else{
						_this.$set(item,'task_allocation_limit',false);
					}
					Object.assign(item, param)
				})
								_this.list.map((item) => {
					let param = {
						source_table: "project_team",
						source_id: item.project_team_id,
						source_user_id: _this.user.user_id
					};
					if(item.cost_report_limit_times > 0){
						_this.$get("~/api/cost_report/count?",param,(result)=>{
							if(result){
								if(result.result >= item.cost_report_limit_times){
									_this.$set(item,'cost_report_limit',true);
								}else{
									_this.$set(item,'cost_report_limit',false);
								}
							}
						})
					}else{
						_this.$set(item,'cost_report_limit',false);
					}
					Object.assign(item, param)
				})
																																																																					},
			get_list_before(param){
				var user_group = this.user.user_group;
				if(user_group != "管理员"){
						let sqlwhere = "(";
										if(user_group=="项目经理"){
						sqlwhere+= "project_manager = " + this.user.user_id + " or ";
					}
																																																												if (sqlwhere.length>1){
						sqlwhere = sqlwhere.substr(0,sqlwhere.length-4);
						sqlwhere += ")";
						param["sqlwhere"] = sqlwhere;
					}
					}
				return param;
			},

																						



				/**
			 * 获取项目经理用户列表
			 */
			async get_list_user_project_manager() {
				var json = await this.$get("~/api/user/get_list?user_group=项目经理");
				if(json.result && json.result.list){
					this.list_user_project_manager = json.result.list;
				}
				else if(json.error){
					console.error(json.error);
				}
			},

			get_user_project_manager(id){
				var obj = this.list_user_project_manager.getObj({"user_id":id});
				var ret = "";
				if(obj){
					ret = obj.nickname+"-"+obj.username;
					// if(obj.nickname){
					// 	ret = obj.nickname;
					// }
					// else{
					// 	ret = obj.username;
					// }
				}
				return ret;
			},
																								},
				created() {
							this.get_list_user_project_manager();
																							}
	}
</script>

<style type="text/css">
	.bg {
		background: white;
	}

	.form.p_4 {
		padding: 1rem;
	}

	.form .el-input {
		width: initial;
	}

	.mt {
		margin-top: 1rem;
	}

	.text_center {
		text-align: center;
	}

	.float-right {
		float: right;
	}


	.modal_wrap{
		width: 100vw;
		height: 100vh;
		position: fixed;
		top: 0;
		left: 0;
		background: rgba(0,0,0,0.5);
		z-index: 9999999999;
	}
	.modal_wrap .modal_box{
		width: 400px;
		height: auto;
		background: url("../../assets/modal_bg.jpg") no-repeat center;
		background-size: cover;
		position: absolute;
		top: 50%;
		left: 50%;
		margin-left: -200px;
		margin-top: -100px;
		border-radius: 10px;
		padding: 10px;
		}
	.modal_wrap .modal_box .modal_box_close{
		font-size: 20px;
		position: absolute;
		top: 10px;
		right: 10px;
		cursor: pointer;
		}
	.modal_wrap .modal_box .modal_box_title{
	  text-align: center;
    font-size: 18px;
    margin: 16px auto;
    color: #fff;
    border-bottom: 1px solid rgba(117, 116, 116,0.5);
    padding-bottom: 16px;
    width: 356px;
		}
	.modal_wrap .modal_box .modal_box_text{
		text-align: center;
		font-size: 14px;
		color: #fff;
		margin: 5px auto;
		width: 90%;
		}
	.modal_wrap .modal_box .btn_box{
		display: flex;
		flex-direction: row;
		justify-content: center;
		margin-top: 42px;
		margin-bottom: 20px;
		}
			.modal_wrap .modal_box .btn_box span{
				display: inline-block;
				width: 80px;
				height: 30px;
				line-height: 30px;
				text-align: center;
				border: 1px solid #ccc;
				font-size: 14px;
				cursor: pointer;
				color: #fff;
			}
	.modal_wrap .modal_box .btn_box span:nth-child(2){
		background: #409EFF;
		color: #fff;
		border-color: #409EFF;
		margin-left: 15px;
	}
	.el-date-editor .el-range-separator{
		width: 10% !important;
	}
</style>
